package cn.iocoder.yudao.module.crm.convert.subject;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.subject.vo.SubjectPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.subject.vo.SubjectRespVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.subject.SubjectDO;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface SubjectConvert {

    SubjectConvert INSTANCE = Mappers.getMapper(SubjectConvert.class);

    default List<SubjectRespVO> convertList(List<SubjectDO> list, SubjectPageReqVO pageReqVO) {
        return CollectionUtils.convertList(list, user -> convert(user, pageReqVO));
    }

    default SubjectRespVO convert(SubjectDO subject, SubjectPageReqVO pageReqVO) {
        SubjectRespVO subjectRespVO = BeanUtils.toBean(subject, SubjectRespVO.class);
        if (StringUtils.isNotBlank(subject.getName())) {
            subjectRespVO.setParentName(pageReqVO.getParentName());
        }
        return subjectRespVO;
    }


}
